<template name="sendcar">
	<!-- 定检计划 -->
	<view class="mypage">

		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入申请人" v-model="keyword"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
			</view>
		</view>

		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in orderList"
				:key="index" @click="openDetail(index)">

				<view class="flex-just-between bottom-border top-wrap">
					<text class="text-blue text-bold"> 单号 ：{{ item.BILLNO || '000' }}</text>
					<view class="cu-capsule radius">
						<view class='cu-tag bg-blue sm'>
							<text class='cuIcon-medal'></text>
						</view>
						<view class="cu-tag line-brown sm">
							{{ index+1}}
						</view>
					</view>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">组织：</text>
					<text>{{ item.ORGNAME || '' }}</text>
				</view>

				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">生产：</text>
					<text>{{ item.DEPTNAME || '' }}</text>
				</view>
				
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">设备：</text>
					<text>{{ item.EQUIPNAME || '' }}</text>
				</view>
				
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">状态：</text>
					<text>{{ item.BILLSTATUS == 1 ?'已巡检' : '未巡检' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text class="card-label text-black">数量：</text>
					<text> {{ item.NUM || '0' }}{{ item.UNIT || '' }} </text>
				</view>
			</view>
		</view>
		<modal title="高级查询" queryType="1" :isShow="isShowModal" @cancelModal="cancelModal" @okModal="okModal"></modal>
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js'
	import utils from '@/common/util.js'

	import modal from "@/components/modal/modal-xj.vue";

	let _self, page = 1,
		total = 1,
		pageTitle, busType, requeryURL;
	let query = {
		// "category": "",
		"page": 1,
		"rows": 10,
		"sidx": "CREATIONTIME",
		"sord": "desc",
		"queryJson": {},
		"userId": "",
		"account": "admin"
	}
	let queryJson = {
		"StartTime": "2020-01-10 00:00:00.00",
		"EndTime": "2029-10-10 23:59:59.999",
	};
	// {BTCATEGORY:1,MOVETYPE:0},
	export default {
		computed: mapState(['userInfo']),
		data() {
			return {
				orderList: [],
				keyword: '',
				busType: 1,
				isShowModal: false,
				SBData: {
					SBID: '',
					SBName: ''
				},
				statusName:{
					"0":'未巡检',
					"1":'维修',
					"2":'更换',
					"3":'正常',
				}
			};
		},
		onLoad(params) {
			_self = this
			// console.log(params);
			page = 1;
			total = 1;
			busType = params.type
			this.busType = params.type
			pageTitle = params.title
			queryJson = {
				"StartTime": "2020-01-10 00:00:00.00",
				"EndTime": "2029-10-10 23:59:59.999",
			};
			// queryJson.INSPCETYPE = params.type
			query.account = this.userInfo.Account
			query.userId = this.userInfo.UserId
			requeryURL = '/API/APPCommon/GetRegularInspection'
			this.getNewsList();
		},
		components: {
			modal
		},
		// 导航栏点击
		onNavigationBarButtonTap(e) {
			console.log(3);
			e.index == 0 ? (this.isShowModal = true) : this.openScanMater();
		},
		//下拉刷新
		onPullDownRefresh: function() {
			// 重置分页及数据
			page = 1;
			total = 1;
			this.orderList = [];
			this.getNewsList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({
				"title": "数据已刷新",
				icon: "none"
			});
		},
		// 加载更多
		onReachBottom: function() {
			this.getNewsList();
		},
		methods: {
			...mapMutations(["setCheckData"]),
			handelSearch() {
				console.log(_self.keyword);
				queryJson.keyword = _self.keyword;
				page = 1;
				total = 1;
				this.orderList = [];
				this.getNewsList();
			},
			// 控制高级查询条件
			cancelModal() {
				this.isShowModal = false;
			},

			okModal(val) {
				this.cancelModal();
				queryJson = {
					...val
				};
				page = 1;
				total = 1;
				this.orderList = [];
				this.getNewsList();
			},
			getNewsList(byType) {
				if (page > total) {
					return uni.showToast({
						icon: 'none',
						title: '没有数据了。'
					})
				}
				query.page = page;
				query.queryJson = JSON.stringify(queryJson);
				// console.log(query);
				// console.log(requeryURL);
				this.axios({
					url: requeryURL,
					data: query,
					isLoading: 1
				}).then(res => {
					let {
						IsSuccess,
						Result,
						Message
					} = res;
					// console.log(res);
					_self.setPageTitle(pageTitle + '列表(' + Result.records + ')')
					_self.orderList = [..._self.orderList, ...Result.rows]
					total = Result.total
					page++
					if (byType == 1) {
						if (!Result.rows.length) {
							_self.needConfirm()
						}
					}
				})
			},

			needConfirm() {
				uni.showModal({
					title: '提示',
					content: '此设备无定检是否需临检？',
					success(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: './submit?title=物资临检&type=0&SBID=' + _self.SBData.SBID + '&SBName=' +
									_self.SBData.SBName
							})
						}
					}
				})
			},

			setPageTitle(d) {
				uni.setNavigationBarTitle({
					title: d
				});
			},

			openDetail(e) {
				uni.$once('refresh',()=>{
					this.handelSearch()
				})

				let Path = '/pages/tab04/patrol/submit?type=' + busType
				_self.setCheckData([_self.orderList[e]])
				uni.navigateTo({
					url: Path
				})
			},

			// 扫描设备
			openScanMater() {
				this.$utils.openScanUtils(0, 0, (res) => {
					if (res.includes('TYPE:8')) {
						let arr = res.split('|');
						let AddItem = {
							PK_EQUIP: '',
							EQUIPNAME: '',
							IMPUNUM: ''
						}
						queryJson.EQUIPNAME = arr[1]
						_self.SBData.SBID = arr[2]
						_self.SBData.SBName = arr[1]
						page = 1;
						total = 1;
						_self.orderList = [];
						_self.getNewsList(1);
					} else {
						this.$utils.tips('非设备二维码,无法使用')
					}
				})
			},

		}
	}
</script>

<style scoped>
	.card-list-wrapper {
		width: 710upx;
		height: 100upx;
		margin: 0 auto;
	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}

	.card-label {
		display: inline-block;
		width: 150upx;
	}

	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, .1);
	}

	.top-wrap {
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, .1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}
</style>